//
//@File    :	14.19_pairs.cpp
//@Time    :	2022/02/24 09:52:18
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	defining and using a Pair template
//

#include <iostream>
#include <string>

template <typename T1,typename T2>
class Pair
{
private:
    T1 a;
    T2 b;
public:
    T1 &first();
    T2 &second();
    T1 first() const{return a;}
    T2 second() const{return b;}
    Pair(const T1&aval,const T2 &bval):a(aval),b(bval){}
    Pair(){}
};

template<typename T1,typename T2>
T1 &Pair<T1,T2>::first()
{
    reurn a;
}

template<typename T1,typename T2>
T2 &Pair<T1,T2>::second()
{
    reurn b;
}

int main()
{
    using std::cout;
    using std::endl;
    using std::string;

    Pair<string,int> ratings[4]={
        Pair<string,int>("The Purpled Duck",5),
        Pair<string,int>("Jaquie's Frisco AI Fresco",4),
        Pair<string,int>("Cafe Souffle",5),
        Pair<string,int>("Bertie's Eats",3)
    };

    int joints = sizeof(ratings)/sizeof(Pair<string,int>);
    cout<<"Rating:\t Eatery\n";
    for (int i = 0; i < joints; i++)
    {
        cout<<ratings[i].second()<<":\t"<<ratings[i].first()<<endl;
    }
    cout<<"Oops!Revised rating:\n";
    ratings[3].first()="Bertie's Fab Eats";
    ratings[3].second()=6;

    cout<<ratings[3].second()<<":\t"<<ratings[3].first()<<endl;
    system("pause");
    return 0;
}


//※模板的具体化speciaization
// 1.隐式实例化
// 2.显式实例化
// 3.显式具体化
// 4.部分具体化
//实例化是生成类声明
//具体化是使用特殊类型替代泛型